package transport

import (
	"context"
	"encoding/json"
	"net/http"
	"sample/endpoint"
)

func HelloRequestDecoder(_ context.Context, r *http.Request) (interface{}, error) {
	var request endpoint.HelloRequest
	err := json.NewDecoder(r.Body).Decode(&request)
	return request, err
}

func HelloResponseEncoder(_ context.Context, w http.ResponseWriter, response interface{}) error {
	w.Header().Set("Content-Type", "application/json")
	return json.NewEncoder(w).Encode(response)
}

func ByeRequestDecoder(_ context.Context, r *http.Request) (interface{}, error) {
	var request endpoint.ByeRequest
	err := json.NewDecoder(r.Body).Decode(&request)
	return request, err
}

func ByeResponseEncoder(_ context.Context, w http.ResponseWriter, response interface{}) error {
	w.Header().Set("Content-Type", "application/json")
	return json.NewEncoder(w).Encode(response)
}
